home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / Frontier / Frontier SDK 2.1 / Toolkits / IAC Tools / iacreceive.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-20  |  3.5 KB  |  171 lines  |  [TEXT/KAHL]

  1. /*© Copyright 1988-1992 UserLand Software, Inc.  All Rights Reserved.*/
  2.  
  3. #include "iacinternal.h"
  4.  
  5.  
  6. /*
  7. 8/24/92 DW: This file includes routines that are likely to be used by code 
  8. that receives Apple Events.
  9. */
  10.  
  11.  
  12. Boolean IACreturnerror (short errn, Str255 errs) {
  13.     
  14.     /*
  15.     return an error string and number in an AppleEvent.
  16.     
  17.     SDK 2.0: if the string is nil or empty, don't push it on the reply.
  18.     */
  19.     
  20.     register AppleEvent *savedevent;
  21.     register Boolean fl;
  22.     
  23.     savedevent = IACglobals.event;
  24.     
  25.     IACglobals.event = IACglobals.reply; /*push params on the reply record*/
  26.     
  27.     fl = true;
  28.     
  29.     if (errs != nil) 
  30.         if (errs [0] > 0)
  31.             fl = IACpushstringparam (errs, keyErrorString);
  32.             
  33.     if (fl)
  34.         fl = IACpushshortparam (errn, keyErrorNumber);
  35.     
  36.     IACglobals.event = savedevent; /*restore*/
  37.     
  38.     return (fl);
  39.     } /*IACreturnerror*/
  40.     
  41.  
  42. void IACnothandlederror (void) {
  43.     
  44.     /*
  45.     call this if you receive an Apple event that you are not set up to handle.
  46.     
  47.     we return the standard "event not handled" error return. you can safely 
  48.     return noErr to the Apple Event Manager.
  49.     */
  50.     
  51.     IACreturnerror (errAEEventNotHandled, nil);
  52.     } /*IACnothandlederror*/
  53.     
  54.     
  55. Boolean IACnextparamisoptional (void) {
  56.     
  57.     IACglobals.nextparamoptional = true;
  58.     } /*IACnextparamisoptional*/
  59.  
  60.  
  61. void IACparamerror (OSErr errn, Str255 typestring, OSType paramkey) {
  62.  
  63.     /*
  64.     build an error string that looks like:
  65.     
  66.         The 'read' verb requires a string parameter with a key of '----'
  67.     
  68.     And return it to the caller.
  69.     */
  70.     
  71.     Str255 errs;
  72.     Str255 bs;
  73.     OSType verbtoken;
  74.     
  75.     if (IACglobals.nextparamoptional) { /*it's not an error, since the caller set this flag*/
  76.     
  77.         IACglobals.nextparamoptional = false; /*must be reset for each param*/
  78.     
  79.         return;
  80.         }
  81.         
  82.     verbtoken = IACgetverbtoken ();
  83.     
  84.     IACcopystring ("\pThe '", errs);
  85.     
  86.     bs [0] = 4;
  87.     
  88.     BlockMove (&verbtoken, &bs [1], 4);
  89.     
  90.     IACpushstring (bs, errs);
  91.     
  92.     IACpushstring ("\p' verb requires a ", errs);
  93.     
  94.     IACpushstring (typestring, errs);
  95.     
  96.     IACpushstring ("\p parameter with a key of '", errs);
  97.     
  98.     bs [0] = 4;
  99.     
  100.     BlockMove (¶mkey, &bs [1], 4);
  101.     
  102.     IACpushstring (bs, errs);
  103.     
  104.     IACpushstring ("\p'", errs);
  105.     
  106.     IACreturnerror (errn, errs);
  107.     } /*IACparamerror*/
  108.     
  109.     
  110. OSType IACgetverbtoken (void) {
  111.     
  112.     /*
  113.     get the id/token of a verb from an AppleEvent
  114.     */
  115.     
  116.     OSType verbtoken;
  117.     
  118.     if (!IACgetlongattr (IACglobals.event, keyEventIDAttr, typeType, (long *) &verbtoken))
  119.         verbtoken = (OSType) 0;
  120.     
  121.     return (verbtoken);
  122.     } /*IACgetverbtoken*/
  123.  
  124.  
  125. OSType IACgetverbclass (void) {
  126.     
  127.     /*
  128.     get the id/token of a verb from an AppleEvent
  129.     */
  130.     
  131.     OSType verbclass;
  132.     
  133.     if (!IACgetlongattr (IACglobals.event, keyEventClassAttr, typeType, (long *) &verbclass))
  134.         verbclass = (OSType) 0;
  135.     
  136.     return (verbclass);
  137.     } /*IACgetverbclass*/
  138.  
  139.  
  140. OSType IACgetsender (void) { 
  141.  
  142.     /*
  143.     get application signature from address attribute. automatically
  144.     invokes our coercion handlers.
  145.     
  146.     this is needed by the Menu Sharing Toolkit -- when the user presses
  147.     cmd-period to halt a script, the next time we get a message from the
  148.     Menu Sharing server (usually Frontier) we return an error. but we only
  149.     return the error if the call came from Frontier, we use this routine
  150.     to identify the sender of the message.
  151.     
  152.     thanks to Kevin Calhoun of Apple Computer for providing this code! 
  153.     */
  154.  
  155.     OSType sender;
  156.     Size actualsize;
  157.     DescType actualtype;
  158.     OSErr errcode;
  159.     
  160.     errcode = AEGetAttributePtr (
  161.         IACglobals.event, keyAddressAttr, typeType, &actualtype, (Ptr) &sender, 
  162.         
  163.         (long) sizeof (sender), &actualsize);
  164.  
  165.     IACglobals.errorcode = errcode;
  166.     
  167.     return (sender);
  168.     } /*IACgetsender*/
  169.  
  170.         
  171.